package com.qf.dao;

import com.qf.entity.User;
import com.qf.utils.JdbcUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.springframework.stereotype.Repository;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author zdl
 * @date 2025/2/7
 */
@Repository
public class UserDao {
   public User selectUserByUser(User user){
       Connection conn = JdbcUtils.getConnection();
       QueryRunner qr = new QueryRunner();
       String sql = "select * from tb_user where username = ? and password = ?";
       try {
           User query = qr.query(conn, sql, new BeanHandler<>(User.class), user.getUsername(), user.getPassword());
           return query;
       } catch (SQLException e) {
           throw new RuntimeException(e);
       }
   }
}
